$(function () {
    $(".btn_getCode").on('tap', function () {
        $.ajax({
            url: "/user/vCode",
            type: "GET",
            success: function (res) {
                console.log(res)
                // var getcode= res;
                // return getcode;
            }
        })
    })

    $(".btn_register").on('tap', function () {
        var radio = $(".myradio").prop("checked")
        if(radio==false){
            mui.toast("请勾选同意协议")
            return;
        }
        var tele = $.trim($("[name='mobile']").val())
        var user = $.trim($("[name='username']").val())
        var pass = $.trim($("[name='pass']").val())
        var pass2 = $.trim($("[name='rePass']").val())
        var code = $.trim($("[name='code']").val())
        
        if(!user){
            mui.toast("请输入用户名")
            return;
        }
        if(!/^[1][3,4,5,7,8][0-9]{9}$/.test(tele)){
            mui.toast("请输入正确的手机号码")
            return;
        }
        if(!pass){
            mui.toast("请设置密码")
            return;
        }
        if(pass!=pass2){
            mui.toast("两次输入的密码不一致")
            return;
        }
        if(!/^\d{6}$/.test(code)){
            mui.toast("请输入正确的验证码")
            return;
        }
        $.ajax({
            url: ' /user/register',
            type: 'POST',
            dataType: "json",
            data: {
                username:user,
                mobile: tele,
                password: pass,
                vCode: code
            },
            beforeSend:function(){
                $(".mylogin").html("正在注册........")
            },
            success: function (res) {
               if(res.success){
                mui.toast("注册成功")
                setTimeout(() => {
                    $(".mylogin").html("正在注册........")
                    location.href = "login.html"
                }, 2000);
                $(".mylogin").html("注册")
               }else{
                   mui.toast(res.message)
               }
            }

        })
    })

})